#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from orioluspith.packets.version import Version
from orioluspith.packets.versionrange import VersionRange

class Meta:
    def __init__(self, name, version, description, conflicts, replaces, depends):
        self.name = name
        self.version = version
        self.description = description
        self.conflicts = conflicts
        self.replaces = replaces
        self.depends = depends

    def is_in_depends(self, name, version_string):
        return self.__contains(name, version_string, self.depends)

    def is_in_replaces(self, name, version_string):
        return self.__contains(name, version_string, self.replaces)

    def is_in_conflicts(self, name, version_string):
        return self.__contains(name, version_string, self.conflicts)

    def __contains(self, name, version_string, list):
        version = Version(version_string)

        for each in list:
            each_name = each["Name"]
            version_range = VersionRange(each["Version"])

            if each_name == name and version_range.contains(version):
                return True

        return False